﻿using CL.Business.BLL;
using CL.Enum.Common.Type;
using CL.Game.BLL;
using CL.Redis.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CL.UnionWeb
{
    public partial class PostMsg : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //必须发送post请求, posttype比填参数, 请求业务类型, 其他参数自定义
            if (HttpContext.Current.Request.RequestType == "POST")
            {
                if ("delete_notice" == Request["posttype"].ToString())
                {
                    string strID = Request["noticeID"].ToString();
                    if(!string.IsNullOrEmpty(strID))
                    {
                        NoticeBLL bll = new NoticeBLL();
                        int iNoteiceID = 0;
                        int.TryParse(strID, out iNoteiceID);
                        var bOk = bll.DelEntity(iNoteiceID);
                        if(bOk)
                        {
                            ReturnMsg("ok");
                        }
                        else
                        {
                            ReturnMsg("删除失败!");
                        }
                    }
                }
                else if ("getcode" == Request["posttype"].ToString())
                {
                    string phoneNum = Request["phoneNum"].ToString();
                    var reg = new Regex("^1[34578]\\d{9}$");
                    var mg = reg.Match(phoneNum);
                    if (mg.Success)
                    {
                        var Entity = new BaseRedis().VerifyTokenRedis(string.Empty, "web");
                        if (null != Entity)
                        {
                            var result = new UsersBLL().SendVerifyCode("web", Entity.Token, phoneNum, (int)VerifyTypeEnum.Register);
                            if (0 == result.Code)
                            {
                                ReturnMsg("ok");
                            }
                            else
                            {
                                ReturnMsg(result.Msg);
                            }
                        }
                        else
                        {
                            ReturnMsg("获取token失败!!");
                        }
                    }
                    else
                    {
                        ReturnMsg("手机号码不正确!!");
                    }
                }
                else if("getcodeforforgetpsw" == Request["posttype"].ToString())
                {
                    string phoneNum = Request["phoneNum"].ToString();
                    var reg = new Regex("^1[34578]\\d{9}$");
                    var mg = reg.Match(phoneNum);
                    if (mg.Success)
                    {
                        var Entity = new BaseRedis().VerifyTokenRedis(string.Empty, "web");
                        if (null != Entity)
                        {
                            var result = new UsersBLL().SendVerifyCode("web", Entity.Token, phoneNum, (int)VerifyTypeEnum.RetrievePwd);
                            if (0 == result.Code)
                            {
                                ReturnMsg("ok");
                            }
                            else
                            {
                                ReturnMsg(result.Msg);
                            }
                        }
                        else
                        {
                            ReturnMsg("获取token失败!!");
                        }
                    }
                    else
                    {
                        ReturnMsg("手机号码不正确!!");
                    }
                }
                else
                {
                    ReturnMsg("请求参数错误!!");
                }
            }
        }

        protected void ReturnMsg(string strMsg)
        {
            Response.Write(strMsg);
            Response.End();
        }
    }
}